<!-- 检测项目 -->
<template>
	<view class="page" style="height: 100vh; background-color: #FFFFFF;">
		<cu-custom bgColor="bg-white" :isBack="true">
			<block style="color: #777777;font-size: 32rpx;" slot="content">检测项</block>
		</cu-custom>
		<u-form :model="itemData" ref="feedbackForm" label-width="100px" style="padding: 24rpx;">
			<u-form-item label-position="left" borderBottom label="所属项目">
				{{itemData.projectName}}
			</u-form-item>
			<u-form-item label-position="left" borderBottom label="标准要求">
				{{itemData.name}}
			</u-form-item>
			<u-form-item label-position="left" borderBottom label="类别">
				{{itemData.standardType || ''}}
			</u-form-item>
			<!-- 手动录入 -->
			<view v-if="itemData.numSet=='1'">
				<u-form-item label-position="left" borderBottom label="总数" prop="total">
					<u-input type="number" border="surround" placeholder="请输入总数" v-model="itemData.total" />
				</u-form-item>
				<u-form-item label-position="left" borderBottom label="不合格数量" prop="fail">
					<u-input type="number" border="surround" placeholder="请输入不合格数量" v-model="itemData.fail" />
				</u-form-item>
			</view>
			<!-- 单一数量 itemData.numSet=='2'"-->
			<view v-if="itemData.numSet=='2'">
				<u-form-item label-position="left" borderBottom label="是否合格">
					<u-radio-group v-model="isGood" placement="row" @change="groupChange()">
						<u-radio :name="true" :customStyle="{marginRight: '10px'}" activeColor="green" label="合格" />
						<u-radio :name="false" activeColor="red" label="不合格" />
					</u-radio-group>
				</u-form-item>
			</view>
			<!-- 绑定设备的检测项 v-if="this.bind" -->
			<view v-if="this.bind">
				<u-button @click="devClick()" type="success" style="margin: 24rpx;">检测设备情况</u-button>
				<u-form-item label-position="left" borderBottom label="总数">
					{{itemData.total || 0}}
				</u-form-item>
				<u-form-item label-position="left" borderBottom label="不合格数量">
					{{itemData.fail || 0}}
				</u-form-item>
			</view>
			<u-form-item label-position="left" borderBottom label="简述检测情况" prop="situation">
				<u-textarea v-model="itemData.situation" placeholder="请输入检测情况"></u-textarea>
			</u-form-item>
		</u-form>

		<view class="padding flex flex-direction">
			<button class="cu-btn margin-tb-sm lg my-btn" v-show="itemData.index != 0" @click="last()">上一步</button>
			<button class="cu-btn margin-tb-sm lg my-btn" v-show="submitShow" @click="submit()">提交</button>
			<button class="cu-btn margin-tb-sm lg my-btn" v-show="!submitShow" @click="submit()">下一步</button>
		</view>
		<message />
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				border: true,
				testItem: {
					taskId: "",
					code: "",
					status: null
				},
				totalNum: 0,
				itemData: {},
				isGood: 0,
				bind: false,
				devType: '',
				submitShow: false
			}
		},
		onLoad(e) {
			this.testItem.taskId = e.taskId
			this.testItem.code = e.code
			this.testItem.status = e.status ? parseInt(e.status) : null
			this.testItem.index = e.index ? parseInt(e.index) : null
			this.totalNum = e.totalNum ? parseInt(e.totalNum) : null
			this.bind = e.bind == 'true' ? true : false 
			this.devType = e.devType
		},
		onShow() {
			this.initView()
		},
		methods: {
			groupChange(n) {
				console.log('groupChange', n);
			},
			devClick() {
				if (this.itemData.signal) {
					uni.navigateTo({
						url: '/jcqy/jcxm/signalList?taskId=' + this.testItem.taskId + '&devType=' + this.devType
					})
				} else {
					uni.navigateTo({
						url: '/jcqy/jcxm/devList?taskId=' + this.testItem.taskId + '&devType=' + this
							.devType //+ '&checkStyle='+this.testItem.checkStyle
					})
				}
			},
			initView() {
				this.getInExamineStandard(this.testItem)
			},
			getInExamineStandard(val) {
				this.itemData = {}
				let params = {
					"taskId": val.taskId,
					"code": val.code,
					"index": val.index,
					"status": val.status
				}
				const _this = this;
				let app = getApp()
				app.globalData.request({
					url: '/wx/examine/getInExamineStandard',
					data: params
				}).then(function(res) {
					_this.itemData = res.data.data
					if(_this.itemData.index == _this.totalNum-1){
						_this.submitShow = true
					}
					_this.testItem.index = _this.itemData.index
				}).catch(function(e) {})
			},
			prePage() {
				uni.navigateTo({
					url: '/jcqy/jcxm/jcxm?taskId=' + this.testItem.taskId + '&code=' + this.testItem.code +
						'&status=' + this.testItem.status + '&totalNum=' + this.totalNum + '&index=' + this
						.testItem.index
				})
			},
			submit() {
				this.testItem.index++
				let _this = this
				// 生成报警信息
				let app = getApp()
				app.globalData.request({
					url: '/wx/examine/saveInExamineStandard',
					data: _this.itemData
				}).then(function(res) {
					if (_this.submitShow) {
						_this.$refs.uToast.show({
							message: "提交成功",
							type: 'success',
							complete() {
								uni.navigateTo({
									url: '/jcqy/jcxq/jcxq?ucId=' + _this.itemData.taskId,
								})
							}
						})
					} else {
						_this.prePage()
					}
				}).catch(function(e) {})
			},
			last(){
				this.testItem.index--
				this.prePage()
			}
		}
	}
</script>

<style lang="scss">
	.u-form {
		padding: 24px;
	}

	.my-btn {
		height: 94rpx;
		background-image: linear-gradient(90deg, #FAB53A 4%, #EFA21A 99%);
		box-shadow: 0 0 12px 0 rgba(250, 181, 58, 0.50);
		border-radius: 24px;
		ont-family: PingFangSC-Medium;
		color: #FFFFFF;
		letter-spacing: 0;
		text-align: center;
	}
</style>
